package com.ruoyi.staffSys.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.staffSys.domain.TbStaff;
import com.ruoyi.staffSys.service.ITbStaffService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工作人员Controller
 * 
 * @author ruoyi
 * @date 2025-11-05
 */
@RestController
@RequestMapping("/staffSys/staff")
public class TbStaffController extends BaseController
{
    @Autowired
    private ITbStaffService tbStaffService;

    /**
     * 游客查询员工
     * @param tbStaff
     * @return
     */
    @GetMapping("/public/list")
    public TableDataInfo publicStaffList(TbStaff tbStaff)
    {
        startPage();
        List<TbStaff> list = tbStaffService.selectTbStaffList(tbStaff);
        return getDataTable(list);
    }

    /**
     * 游客查询员工详细信息
     * @param id
     * @return
     */
    @GetMapping(value = "/public/{id}")
    public AjaxResult publicGetInfo(@PathVariable("id") Long id)
    {
        return success(tbStaffService.selectTbStaffById(id));
    }
    /**
     * 查询工作人员列表
     */
    @PreAuthorize("@ss.hasPermi('staffSys:staff:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbStaff tbStaff)
    {
        startPage();
        List<TbStaff> list = tbStaffService.selectTbStaffList(tbStaff);
        return getDataTable(list);
    }

    /**
     * 导出工作人员列表
     */
    @PreAuthorize("@ss.hasPermi('staffSys:staff:export')")
    @Log(title = "工作人员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbStaff tbStaff)
    {
        List<TbStaff> list = tbStaffService.selectTbStaffList(tbStaff);
        ExcelUtil<TbStaff> util = new ExcelUtil<TbStaff>(TbStaff.class);
        util.exportExcel(response, list, "工作人员数据");
    }

    /**
     * 获取工作人员详细信息
     */
    @PreAuthorize("@ss.hasPermi('staffSys:staff:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbStaffService.selectTbStaffById(id));
    }

    /**
     * 新增工作人员
     */
    @PreAuthorize("@ss.hasPermi('staffSys:staff:add')")
    @Log(title = "工作人员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbStaff tbStaff)
    {
        return toAjax(tbStaffService.insertTbStaff(tbStaff));
    }

    /**
     * 修改工作人员
     */
    @PreAuthorize("@ss.hasPermi('staffSys:staff:edit')")
    @Log(title = "工作人员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbStaff tbStaff)
    {
        return toAjax(tbStaffService.updateTbStaff(tbStaff));
    }

    /**
     * 删除工作人员
     */
    @PreAuthorize("@ss.hasPermi('staffSys:staff:remove')")
    @Log(title = "工作人员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbStaffService.deleteTbStaffByIds(ids));
    }
}
